package com.star.star.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.star.star.dto.StarAlbumArtPageWxuserDTO;
import com.star.star.entity.StarAlbumArt;
import com.star.star.mapper.StarAlbumArtMapper;
import com.star.star.service.StarAlbumArtService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.star.star.vo.StarAlbumArtPageWxuserVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 艺人专辑关联作品 服务实现类
 *
 * @author yangzj
 */
@Service
public class StarAlbumArtServiceImpl extends ServiceImpl<StarAlbumArtMapper, StarAlbumArt> implements StarAlbumArtService {

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void saveWxuser(Long albumId, Long artId) {
        if(albumId == null){
            return;
        }
        this.save(new StarAlbumArt().setAlbumId(albumId).setArtId(artId));
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void updateWxuser(Long albumId, Long artId) {
        // 先删除再添加
        this.deleteWxuserByArtId(artId);
        this.saveWxuser(albumId, artId);
    }

    @Override
    public void deleteWxuserByArtId(Long artId) {
        this.lambdaUpdate().eq(StarAlbumArt::getArtId, artId).remove();
    }

    @Override
    public void deleteWxuserByArtIds(List<Long> artIds) {
        this.lambdaUpdate().in(StarAlbumArt::getArtId, artIds).remove();
    }

    @Override
    public IPage<StarAlbumArtPageWxuserVO> pageWxuser(StarAlbumArtPageWxuserDTO dto) {
        return baseMapper.pageWxuser(dto);
    }

    @Override
    public List<Long> listArtId(Long albumId) {
        return baseMapper.listArtId(albumId);
    }
}
